package cn.dev;

import cn.dev.entity.Demo;
import cn.dev.entity.Dept;
import cn.dev.entity.User;
import cn.dev.mapper.DeptMapper;
import cn.dev.mapper.TestMapper;
import cn.dev.mapper.UserMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.test.context.junit4.SpringRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author 10219990
 * @date 2023/05/24 08:50
 **/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringbootApplication.class)
public class DemoTestEntity {

    @Resource
    private UserMapper userMapper;
    @Resource
    private TestMapper testMapper;
    @Resource
    private DeptMapper deptMapper;

    @Test
    public void contextLoads() {
        User user = null;
        for (int i = 0; i < 50; i++) {
            user = new User();
            user.setName("何志鹏" + i);
            int randomNum = (int) (Math.random() * 9000 + 1000);
            user.setAge(new Long(randomNum));
            user.setSex("1");
            user.setEducation("1");
            user.setCreationTime(new Date());
            user.setUpdateTime(new Date());
            userMapper.insert(user);
        }
    }

    @Test
    public void insertTest() {
        Demo user = new Demo();
        for (int i = 0; i < 50; i++) {
            user = new Demo();
            user.setName("何志鹏" + i);
            int randomNum = (int) (Math.random() * 9000 + 1000);
            user.setAge(new Long(randomNum));
            testMapper.insert(user);
        }
    }

    @Test
    public void insertDept() {
        Dept user = new Dept();
        for (int i = 0; i < 50; i++) {
            user = new Dept();
            user.setName("何志鹏" + i);
            int randomNum = (int) (Math.random() * 9000 + 1000);
            user.setAge(new Long(randomNum));
            deptMapper.insert(user);
        }
    }


    @Test
    public void selectTest() {
        QueryWrapper<Demo> queryWrapper = new QueryWrapper<>();
        List<Demo> list = testMapper.selectList(queryWrapper);
        System.out.println(list);
        System.out.println(list.size());
    }

    @Test
    public void  deleteTest() {
        QueryWrapper<Demo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Demo::getId,1661244342672367617L);
        int count = testMapper.delete(queryWrapper);
        System.out.println(count);
    }


    @Test
    public void selectTDept() {
        QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
        List<Dept> list = deptMapper.selectList(queryWrapper);
        System.out.println(list);
        System.out.println(list.size());
    }

}
